from python.db.actions import _uuid, _types, _show_primary_key, _has_column, _add_column, _show_columns, _show_tables, \
    _has_table, _drop_table, _truncate_table, _rename_table, _create_table, _insert_handler, _update_handler, \
    _delete_handler, _update_by_id_handler, _save_handler, _select_handler, _select_where_handler, _page_handler


class DBConfig:

    @staticmethod
    def uuid():
        return _uuid()

    @staticmethod
    def types():
        return _types()

    @staticmethod
    def primary_key():
        return _show_primary_key()

    @staticmethod
    def tables():
        return _show_tables()


class Table:
    def __init__(self, name):
        self.name = f"tb_{name}"

    def create_column(self):
        return Column(self.name)

    def columns(self, include_primary_key):
        return _show_columns(self.name, include_primary_key)

    def has(self):
        return _has_table(self.name)

    def drop(self):
        return _drop_table(self.name)

    def truncate(self):
        return _truncate_table(self.name)

    def rename(self, update_name):
        return _rename_table(self.name, update_name)

    def create(self, data):
        return _create_table(self.name, data)

    def insert(self, data):
        return _insert_handler(self.name, data)

    def update(self, where, data):
        return _update_handler(self.name, where, data)

    def delete(self, where):
        return _delete_handler(self.name, where)

    def update_by_id(self, data):
        return _update_by_id_handler(self.name, data)

    def delete_by_id(self, _id):
        return _update_by_id_handler(self.name, _id)

    def save(self, data):
        return _save_handler(self.name, data)

    def select(self, methods=None):
        if methods is None:
            methods = {}
        return _select_handler(self.name, methods)

    def select_conditional(self, where=None):
        if where is None:
            where = {}
        return _select_where_handler(self.name, where)

    def page(self, page):
        return _page_handler(self.name, page)


class Column:

    def __init__(self, name):
        self.name = name

    def has(self, name):
        return _has_column(self.name, name)

    def drop(self, column):
        return _has_column(self.name, column)

    def add(self, column):
        return _add_column(self.name, column)

    def rename(self, column):
        return _add_column(self.name, column)
